package com.pd.backend.service.impl;

import com.pd.backend.entity.PdCoreOrg;
import com.pd.backend.dao.PdCoreOrgDao;
import com.pd.backend.service.PdCoreOrgService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 组织(PdCoreOrg)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:32
 */
@Service("pdCoreOrgService")
public class PdCoreOrgServiceImpl implements PdCoreOrgService {
    @Resource
    private PdCoreOrgDao pdCoreOrgDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdCoreOrg queryById(Long id) {
        return this.pdCoreOrgDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdCoreOrg   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdCoreOrg> queryByPage(PdCoreOrg pdCoreOrg, PageRequest pageRequest) {
        long total = this.pdCoreOrgDao.count(pdCoreOrg);
        return new PageImpl<>(this.pdCoreOrgDao.queryAllByLimit(pdCoreOrg, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdCoreOrg 实例对象
     * @return 实例对象
     */
    @Override
    public PdCoreOrg insert(PdCoreOrg pdCoreOrg) {
        this.pdCoreOrgDao.insert(pdCoreOrg);
        return pdCoreOrg;
    }

    /**
     * 修改数据
     *
     * @param pdCoreOrg 实例对象
     * @return 实例对象
     */
    @Override
    public PdCoreOrg update(PdCoreOrg pdCoreOrg) {
        this.pdCoreOrgDao.update(pdCoreOrg);
        return this.queryById(pdCoreOrg.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.pdCoreOrgDao.deleteById(id) > 0;
    }
}
